/*
 * @Description: 引擎-容器中心（可控、可管理）
 */

const globeCollection = {
	arcGis: {},//ArcGis 集合
	tMap: {},//天地图 集合
	tileset: {},//模型加载 集合
	models: {},//手工小模型加载 集合
	terrain: null,
	decalLayer: null,
	billboardCollection: {},
	geoFencing: {},
	roadBuffer: {},
	urlTemplateImageryProvider: {},
	superMap: {},
	label3D: {},
	polygon3D: {},
	polyline3D: {},
	plane3D: {},
	wall3D: {},
	s3mtileset: {},
	tilesetLayer: {},
	flattenMask: {},
	clipVolume: {},
	meshLayer: {},
	projectionLayer: null, //公共的投影图层并且唯一
	projectionLayers: {},
	projectionDataSource: {},
	ProjectionNode: {},
	geoJsonModel: {},
	geoJsonPolylineLayer: {},
	geoJsonPolygonLayer: {},
	particle: {},
	dom: {},
	frameAction: {
		domMark: null,
	},
	extrudeEntity: {},
	trackAnimation: {},
	modelLayer: {},
	bimPullOut: {},
	wmsImagery: {},
	geoJsonPointLayer: {},
	globeEntity: {},
}

function getBase3DTilesetById(id) {
	if (id === 'globe') {
		return {
			type: 'globe',
			layer: window.viewer.scene.globe,
		}
	}
	const tilesetList = [...Object.keys(globeCollection.tileset)]
	const tilesetId = tilesetList.find((i) => i === id)
	if (tilesetId) {
		return {
			type: 'tileset',
			layer: globeCollection.tileset[tilesetId],
		}
	}
	const tilesetLayerList = [
		...Object.keys(globeCollection.tilesetLayer),
	]
	const tilesetLayerId = tilesetLayerList.find((i) => id === id)
	if (tilesetLayerId) {
		return {
			type: 'tilesetLayer',
			layer: globeCollection.tilesetLayer[tilesetLayerId],
		}
	}

	return {}
}

function getEntityById(id) {
	const keys = Object.keys(globeCollection)
	const type = keys.find((k) => {
		if (!globeCollection[k]) return
		return Object.keys(globeCollection[k]).find((i) => i === id)
	})
	if (!type) {
		console.error("id is not exist")
		return
	}
	return globeCollection[type][id]
}

export { globeCollection, getBase3DTilesetById, getEntityById }
